package com.wu.framework.oauth.servie.impl;

import com.wu.framework.oauth.domain.entity.OauthClientDetails;
import com.wu.framework.oauth.persistence.jpa.OauthClientDetailsJpaRepository;
import com.wu.framework.oauth.servie.OauthClientDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * description
 *
 * @author 吴佳伟
 * @date 2021/5/26 4:37 下午
 */
@Service
public class OauthClientDetailsServiceImpl implements OauthClientDetailsService {

    private final OauthClientDetailsJpaRepository oauthClientDetailsJpaRepository;
    private final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    public OauthClientDetailsServiceImpl(OauthClientDetailsJpaRepository oauthClientDetailsJpaRepository) {
        this.oauthClientDetailsJpaRepository = oauthClientDetailsJpaRepository;
    }

    @Override
    public OauthClientDetails saveOauthClientDetails(OauthClientDetails oauthClientDetails) {
        oauthClientDetails.setClientSecret(passwordEncoder.encode(oauthClientDetails.getClientSecret()));
        return oauthClientDetailsJpaRepository.save(oauthClientDetails);
    }

}
